/**************************************
 * Subcategory Selected Change
 *************************************/
$(document).ready(
    function(){
        $('#id_category').change(function(){
            category_value = $(this).val();
            change_subcategory_select(category_value);
        });
        $('.need-confirm-delete-link').live('click', function(){
            if(confirm('Do you want to delete it?')){
                return true;
            }
            return false;
        });
    }
);
/**
 * Change subcategory selected 
 **/
function change_subcategory_select(category_value){
    $('#id_subcategory').empty()
    if(category_value&&category_value!=''){
        url = '/get/subcategory/'+category_value;
        $.getJSON(url, function(data){
            for(var key in data){
                subcategory = data[key];
                sub_option = $('<option/>').val(key).text(subcategory);
                $('#id_subcategory').append(sub_option);                
            }
        });
    }
}

/********************************************
 * Confirm delete action
 ********************************************/
function confirm_delete_button(){
    if(confirm('Are you realy want to delete it?')){
        window.location.href = 'delete';
    }
}

function confirm_order_operation(action){
    if(confirm('You are doing '+action+' operation.')){
        $('#order_opperation').val(action);
        document.forms.order_operation_form.submit()
    }
}
